*===============================================================================
* Project title		Savings Accounts to Borrow Less	
* PIs			Felipe Kast, Dina Pomeranz 
* File name		inTextAnalysis.do
*-------------------------------------------------------------------------------
* Description		Generate numbers stated in the text, not from tables  
* Outputs		inTextLog.smcl
* Spaces per tab 	8 
*===============================================================================

*===============================================================================
* START
*===============================================================================

*===============================================================================
* I. Preamble
*===============================================================================
*-------------------------------------------------------------------------------
* I.1. Set-up
*-------------------------------------------------------------------------------
global path "~/file_server/project_savings/2_shared/impact/do/November2019"	// Path to processed data
global inputPath "$path/datasets"
global results "$path/results"
cd "$results"									// Change to directory to store results
set more off
	// Start log
	cap log close
	log using "inTextLog.smcl"

*===============================================================================
* II. Analysis
*===============================================================================
*-------------------------------------------------------------------------------
* II.1. Introduction
*-------------------------------------------------------------------------------
*Page 3
/*"In a randomized  field experiment among over 3,500 low-income members of a 
microfinance institution in Chile" [...].*/
*3,582 actually (3,500 for a cleaner number)
use "$inputPath/impactDatabase.dta", clear
sum inSample if inSample==1
*Dividing by 2 because this is a two-period panel dataset
local estsample=r(N)/2
di `estsample'
*3582

*Page 3
/* The probability of
having loans with informal networks of friends and family, providers of basic services and utilities,
business partners and money lenders falls and total short-term debt is reduced by between 2% and
22%,1 mainly driven by debt to family and friends. + Endnote*/

// A) Winsorizing at 5%
use "$inputPath/impactDatabase.dta", clear
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.w5_shortTermBorrowing 
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe w5_shortTermBorrowing c.accountAccess#c.post post if t1 == 1,		///
			abs(idBaseSurvey) vce(cluster groupId)
drop t1
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
sum w5_shortTermBorrowing if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
di 100*`debt_decrease'/`control_mean'
*-21.533 - ca. 22% reduction winsorized at 5%

// B) Winsorizing at 1%
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.w1_shortTermBorrowing 
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe w1_shortTermBorrowing c.accountAccess#c.post post if t1 == 1,		///
			abs(idBaseSurvey) vce(cluster groupId)
drop t1
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
sum w1_shortTermBorrowing if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
di 100*`debt_decrease'/`control_mean'
*-12.806- ca. 13% reduction winsorized at 1%

// c) No winsorizing
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.w1_shortTermBorrowing 
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe shortTermBorrowing c.accountAccess#c.post post if t1 == 1,		///
			abs(idBaseSurvey) vce(cluster groupId)
drop t1
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
sum shortTermBorrowing if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
di 100*`debt_decrease'/`control_mean'
*-1.5586- ca. 2% reduction for non-winsorized

*Page 3
/*"The need to reduce consumption when experiencing an economic shock is reduced
by 47%."*/
use "$inputPath/impactDatabase.dta", clear
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.numberConsumptionCutbacks
egen t1 = max(e(sample)), by(idBaseSurvey)
* Triple difference for consumption cutbacks					
reghdfe numberConsumptionCutbacks c.economicShock#c.accountAccess#c.post 	///
	c.accountAccess#c.post c.economicShock#c.post post if t1 == 1,		///
	abs(i.idBaseSurvey) vce(cluster groupId)      
local shock_acc_post = _b[c.economicShock#c.accountAccess#c.post]
di `shock_acc_post'
*-.39955245
local shock_post = _b[c.economicShock#c.post]
di `shock_post'
*.84168404
di 100*`shock_acc_post'/`shock_post'
*-47.470598 - ca. 47% reduction of shocks

*Page 3
/*"The improvements correspond to the types of expenditures for which 
participants had expressed desire to build a buffer stock, and their magnitudes 
are in line with the 56,700 Chilean pesos in average (about 113 USD) in average 
deposits made by those who took up the account."*/
/*"Descriptive Statistics On Take-Up and Account Usage Among Treated 
Individuals" table result*/
*Actual number is 56,721 (56,700 for a cleaner number)
sum totalDepositedJul08Aug09 if activeUser == 1 & inSample == 1, d
local totalDep = r(mean)
di `totalDep'
*56721.421
di `totalDep'/500									
*113.44284 - ca. 113 USD effect on expenditures

*Page 4
/*"Participants experience substantial improvements in subjective well-being, 
both backward-looking - they evaluate recent economic diffculties as less severe 
- and forward-looking - they experience less anxiety about their financial 
future. The magnitudes of these improvements are large and correspond to about more 
than half of the change in these well-being measures associated with a job loss 
or severe business downturn."*/
/*we are dividing the coefficients from the regressions in the "Self-Reported 
Economic Well-Being" table*/
use "$inputPath/impactDatabase.dta", clear
local i = 1
*The order of the loops mean 1 is for anxietyFuture and 2 for economicDifficulty
foreach y in anxietyFuture economicDifficulty {
 reg d.`y'
 egen t1 = max(e(sample)), by(idBaseSurvey)
 
 reghdfe `y' c.accountAccess#c.post post if t1 == 1, ///
 abs(idBaseSurvey) vce(cluster groupId) 
 local b`i' = _b[c.accountAccess#c.post]

 reghdfe `y' c.jobLoss#c.post post if t1 == 1,  	///
 abs(idBaseSurvey) vce(cluster groupId) 
 local jobLoss`i' = _b[c.jobLoss#c.post]
 
 reghdfe `y' c.bizDown#c.post post if t1 == 1,  	///
 abs(idBaseSurvey) vce(cluster groupId)
 local bizDown`i' = _b[c.bizDown#c.post]
 
 drop t1
 local i = `i' + 1
}
di `b1' // Treat effect on future anxiety
*-.11643102
di `jobLoss1' // Effect of job loss on future anxiety
*.104239
di `bizDown1' // Effect of business loss on future anxiety
*.20306369
di `b2'		// Treat effect on current sense of ec. difficulty
*-.0905318
di `jobLoss2' // Effect of job loss on sense of ec. difficulty
*.15213139
di `bizDown2' // Effect of business loss on sense of ec. difficulty
*.17266993
//Ratios:
di `: display %10.2fc `b1'/`jobLoss1''
*-1.12
di `: display %10.2fc `b1'/`bizDown1''
*-.57
di `: display %10.2fc `b2'/`jobLoss2''
*-.6
di `: display %10.2fc `b2'/`bizDown2''
*-.52
/*The negative signs denote improvements in subjective well-being since they
indicate decreases in anxiety about the future and economic difficulty and the 
ratios show that the accounts decrease the difficulty and anxiety by about 
half and more of what these economics shocks decrease*/

*Page 4 
/*"Half of the treatment group additionally had access to a commitment device based on self-help
peer groups. In a separate study (Kast et al., 2018), we find that those who received this treatment
have significantly higher savings."*/
use "$inputPath/impactDatabase.dta", clear
*The treatment group is defined as those that had access to an account
sum accountAccess if accountAccess==1
local treatmentgrp = r(N)
di `treatmentgrp'
*5374
sum peerGroupTreatment if peerGroupTreatment==1
local peergrp = r(N)
di `peergrp'
*2926
di 100*`peergrp'/`treatmentgrp'
*54.447339 = 54.45% = about half

*-------------------------------------------------------------------------------
* II.2. Section 2: Background, Data and Study Design
*-------------------------------------------------------------------------------
*-------------------------------------------------------------------------------
* II.2.a. Section 2.1: Background and Data
*-------------------------------------------------------------------------------
*Page 8
*"About 91% are women"
use "$inputPath/impactDatabase.dta", clear
*Getting total number of participants first
sum inSample if inSample==1 & post==0							
local estsample = r(N)
di `estsample'
*3582
*Now all female participants
sum female if female==1 & post==0
local female = r(N)
di `female'
*3264
*Percentage:
di 100*`female'/`estsample'
*91.122278 = 91%

*Page 9
/*"the baseline survey was conducted among 307 groups of Fondo Esperanza's 
(FE's) members."*/
use "$inputPath/impactDatabase.dta", clear
qui tab groupId
local all_groups = r(r)
di `all_groups'
*307 // total number of number saving groups 


/*Study participants have low incomes compared to the general population in Chile. 
Mean household income in our sample is around 340,000 Chilean pesos */

use "$inputPath/impactDatabase.dta", clear
gen hhinc = householdSize * incomePerCap
sum hhinc if post == 0
* Mean 318389.6
sum hhinc if post == 1
* Mean 329475.7

*Page 9
/*"Two-thirds of the groups were randomly selected to be offered a free savings 
account while the control group was not eligible for this type of savings 
account."*/
use "$inputPath/impactDatabase.dta", clear
qui tab groupId
local all_groups = r(r)
di `all_groups'
*307
qui tab groupId if accountAccess==1
di 100*r(r)/`all_groups'
*63.843648 // ca.  two-thirds of groups are treated

*Page 9
/*"A subgroup of one quarter of treated groups was randomly assigned to receive 
a preferential interest rate of 5%, and in half of the treated groups, 
self-control problems were additionally reduced through a peer group commitment 
mechanism."*/
use "$inputPath/impactDatabase.dta", clear
count if accountAccess==1 & post == 0
local treatmentgrp = r(N)
di `treatmentgrp'
*2687
count if peerGroupTreatment==1 & post == 0
local peergrp = r(N)
di `peergrp'
*1463
count if highInterestTreatment==1 & post == 0
local hintgrp = r(N)
di `hintgrp'
*653
di 100*`peergrp'/`treatmentgrp'
*54.447339 // Assignment to peer group: 54% = about half
di 100*`hintgrp'/`treatmentgrp'
*24.302196 // Assignment to high-interest group: 24% = roughly a quarter

*-------------------------------------------------------------------------------
* II.2.b. Section 2.3: Balance of Randomization and Baseline Summary Statistics
*-------------------------------------------------------------------------------
*Page 13 
/*"we find that those who experienced a job loss in the household or a 
significant downturn of their business in the preceding three months reported 
cutting back consumption in 53% more categories than those who did not."*/
use "$inputPath/impactDatabase.dta", clear
sum numberConsumptionCutbacks if economicShock==1 & post == 1
local shock_cutback = r(mean)
di `shock_cutback'
*2.656446
sum numberConsumptionCutbacks if economicShock==0 & post == 1
local no_shock_cutback = r(mean)
di `no_shock_cutback'
*1.7377736
di 100*`shock_cutback'/`no_shock_cutback'
*152.8649 = 53% more

*Page 13
/*"The backward-looking measure was asked after the specific questions about 
participants' recent economic shocks, consumption etc. in order to allow 
participants to recall and evaluate their recent economic situation more 
accurately. The question on recent economic difficulties asks, "In sum, 
thinking about all the economic difficulties of the last three months, on a 
scale of one to ten, how difficult was this situation for you?" The mean answer 
was 5.1"*/
use "$inputPath/impactDatabase.dta", clear
*We only want the year 2008 for this statement
sum economicDifficultyAnswer if year==2008
di r(mean)
*5.1178336

*Page 13
/*"In the follow-up survey, conducted one year after the introduction of the accounts, 593 (14.2
percent) of the original 4,175 participants from the baseline could not be found by the survey
agency."*/
*Table 1 results
use "$inputPath/impactDatabase.dta", clear
sum inSample if inSample != 1 & year==2009
local attrition = r(N)
di `attrition'
*593 // attritors
sum accountAccess if accountAccess != . & year==2009
local all_participants = r(N)
di `all_participants'
*4175 // total population size in baseline
di 100*`attrition'/`all_participants'
*14.203593 // ca. 14.2 pct. attrition

*Page 14
/*"However, attrition is 2.9 percentage points higher in
the treatment group and attritors and non-attritors differ along several characteristics (shown in
Columns (5) and (6))"*/
/*"Baseline Summary Statistics and Balance of Randomization" table results: 0.03 
from third to last row (Attrition result), unbalanced characteristics appear as 
significant in Column 6 and the balance between treatment and control can be 
seen from the non-significant differences in Column 4*/
use "$inputPath/impactDatabase.dta", clear
//special cells, row 1 & 2
gen attrition = (inSample != 1)
sum attrition if accountAccess == 0
local c2r1 = trim("`: display %12.2fc r(mean)'") 
local c2r2 = trim("`: display %12.2fc r(sd)'") 
reg attrition accountAccess
local attrition_pct = _b[accountAccess]
di `attrition_pct' 
*.02855845  // ca. 2.9 pct. differential attrition

*-------------------------------------------------------------------------------
* II.3. Section 3: Results
*-------------------------------------------------------------------------------
*-------------------------------------------------------------------------------
* II.3.a. Section 3.1: Impact of Access to a Savings Account
*-------------------------------------------------------------------------------
// ACCOUNT USAGE
*Page 14
/*"They deposited an average of 56,700 pesos in total (about 113 USD) with a 
median of 4,000 pesos."*/
/*"Descriptive Statistics On Take-Up and Account Usage Among Treated Individuals" 
table, Column 1 and Column 2*/
use "$inputPath/impactDatabase.dta", clear
sum totalDepositedJul08Aug09 if activeUser == 1 & inSample == 1, d
local totalDep = r(mean)
di `totalDep'
*56721.421 CPL
di `totalDep'/500									
*113.44284 // mean deposit is ca. 113 USD

*Page 14
/*"The average number of withdrawals was 1 and the total amount withdrawn was 
46,200 (about 95 USD) on average."*/
/*"Descriptive Statistics On Take-Up and Account Usage Among Treated Individuals" 
table, Column 1*/
use "$inputPath/impactDatabase.dta", clear
sum totalWithdrawalJul08Aug09 if activeUser == 1 & inSample == 1, d
local totalWith = r(mean)
di `totalWith'
*47488.703 CPL
di `totalWith'/500	
*94.977406 // mean withdrawal was 95 USD

*Page 14
/*"Over the year of the study, participants held an average monthly savings 
balance of around 18,300 Chilean pesos (about 37 USD)."*/
/*"Descriptive Statistics On Take-Up and Account Usage Among Treated Individuals" 
table, Column 1*/
use "$inputPath/impactDatabase.dta", clear
sum avgMonthSavingsAug08Aug09 if activeUser == 1 & inSample == 1, d
local avgSavings = r(mean)
di `avgSavings'
*18269.461 CPL
di `avgSavings'/500	

*Page 14
*"This balance amount represents about 23% of monthly income"
use "$inputPath/impactDatabase.dta", clear
sum avgMonthSavingsAug08Aug09 if activeUser == 1 & inSample == 1, d
local avg_monthly_sav_active = r(mean)
di `avg_monthly_sav_active'
*18269.461
sum incomePerCapita if accountAccess == 0
local avg_monthly_income = r(mean)
di `avg_monthly_income'
*79954.901
di `avg_monthly_sav_active'/`avg_monthly_income'
*.22849707 // ca. 23 pct. of avg. monthly income as avg. savings

// BORROWING
*Page 15
/*"Among the specific categories within family and friends, borrowing from 
parents, who are the most frequent category participants borrowed from within 
family and friends, was reduced the most
significant ath the 1% level."*/                                                    
use "$inputPath/impactDatabase.dta", clear
foreach y in borrowParents borrowSonsDaughters borrowSiblings borrowPartner ///
	borrowFriends borrowRelatives {
 quietly: reg d.`y'
 egen t1 = max(e(sample)), by(idBaseSurvey)
 reghdfe `y' c.accountAccess#c.post post if t1 == 1, abs(idBaseSurvey) vce(cluster groupId) 
 count if `y' > 0 & post == 0
 count if `y' > 0 & post == 1
 count if `y' > 0 
 drop t1
}

/*The counts displayed show that borrowing from parents is the most frequent 
which is true whether we look at categories or probability or amounts */

//Regarding the strongest decrese
use "$inputPath/impactDatabase.dta", clear
foreach y in iBorrowParents iBorrowSonsDaughters iBorrowSiblings iBorrowPartner ///
	iBorrowFriends iBorrowRelatives {
 quietly: reg d.`y'
 egen t1 = max(e(sample)), by(idBaseSurvey)
 reghdfe `y' c.accountAccess#c.post post if t1 == 1, abs(idBaseSurvey) vce(cluster groupId) 
 drop t1
}

//Strongest decrease in terms of probability also same as categories. 
foreach y in prborrowParents prborrowSonsDaughters prborrowSiblings prborrowPartner ///
	prborrowFriends prborrowRelatives {
 quietly: reg d.`y'
 egen t1 = max(e(sample)), by(idBaseSurvey)
 reghdfe `y' c.accountAccess#c.post post if t1 == 1, abs(idBaseSurvey) vce(cluster groupId) 
 drop t1
}

*The regression output for borrowParents shows it's significant at the 1% level
* as well as the greatest effect within the family & friends group

*Page 15
/*Panel B shows a reduction of 0.13 categories of borrowing,
significant at the 1% level, for those with access to the account. This represents a decrease of 23%
compared to the control group mean in the post-treatment period.*/
use "$inputPath/impactDatabase.dta", clear
merge m:1 idBaseSurvey using $path/datasets/asesor2008.dta
sort idBaseSurvey year
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.stBorrowTotalIndex 
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe stBorrowTotalIndex c.accountAccess#c.post post  if t1 ==1, abs(idBaseSurvey) ///
			vce(cluster groupId) 
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
*-.13042785
 // Treatment effect on number of short term debt categories
sum stBorrowTotalIndex if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
*.57055215 // avg. categories of short term debt
di 100*`debt_decrease'/`control_mean'
*-22.859936 // number of categories is reduced by about 23%	

*Page 15
/*"Consistent with panel A, we see
that the largest decrease stems from informal borrowing from family and friends, which is reduced
by 0.073, significant at the 1% level19. The effect corresponds to a 37% decrease compared to the
control group mean in the post-treatment period."*/
use "$inputPath/impactDatabase.dta", clear
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.stBorrowFamilyIndex 
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe stBorrowFamilyIndex c.accountAccess#c.post post  if t1 ==1, abs(idBaseSurvey) ///
			vce(cluster groupId) 
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
*-.07346242   // Treatment effect on number of debt categories to family and friends
sum stBorrowFamilyIndex if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
*.19861963   // number of avg. categories of debt to family and freidns
di 100*`debt_decrease'/`control_mean'
*-36.986484 // number of cat. of debt to family and freinds reduced by ca. 37%

*Page 15
/*"The outstanding payments to service providers
decline by 0.055 categories, significant at the 5% level, representing a reduction of 24% compared 
to the control group mean."*/
use "$inputPath/impactDatabase.dta", clear
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.stBorrowProvidersIndex
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe stBorrowProvidersIndex c.accountAccess#c.post post  if t1 ==1, abs(idBaseSurvey) ///
			vce(cluster groupId) 
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
*-.05528393
sum stBorrowProvidersIndex if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
*.23466258
di 100*`debt_decrease'/`control_mean'
*-23.558904  // Reduction of debt to service providers is ca. 24%

*Page 15
/*"Within the components of outstanding payments, the reduction in debt with 
utility providers (electric, gas, water, and telephone) is the largest with 39%, 
significant at the 1% level."*/
use "$inputPath/impactDatabase.dta", clear
capture drop t1
foreach y in iBorrowHealth iBorrowSchools iBorrowServProv {
	 quietly: reg d.`y'
	 egen t1 = max(e(sample)), by(idBaseSurvey)
    reghdfe `y' c.accountAccess#c.post post  if t1 ==1, abs(idBaseSurvey) ///
			vce(cluster groupId)  
    sum `y' if accountAccess == 0 & post == 1
	 di "`: display %6.0fc 100*_b[c.accountAccess#c.post]/`r(mean)''%"
	 drop t1
 }
/*The ratios displayed show the biggest decrease is with utility providers (39%), 
and the regression output for iBorrowServProv shows it's significant at the 1% 
level*/

*Page 15-16
/* The amount of outstanding short-term debt declines by 13184 pesos, significant at the 5% level
[...] This represents a reduction of about 22% compared to the post-intervatention mean
in the control group */
// See code above regarding the introduction section

*Page 16
/* Looking at what type of short-term debt is reduced, we see the strongest redcution 
in the amount owerd to family and friends with 6605 pesos, significant at the 1% level.
This represents a 41% reduction compared to the post-intervention control group mean. */
use "$inputPath/impactDatabase.dta", clear
*method used to signal subjects who reported outcome variable in both periods
quietly: reg d.w5_stBorrowFamily 
egen t1 = max(e(sample)), by(idBaseSurvey)
*regression
reghdfe w5_stBorrowFamily c.accountAccess#c.post post if ///
	t1 == 1, abs(idBaseSurvey) vce(cluster groupId)
local debt_decrease = _b[c.accountAccess#c.post]
di `debt_decrease'
*-6604.7266 // Treatment effect on debt owed to family and friends
sum w5_stBorrowFamily if accountAccess == 0 & post == 1 // control's mean outcome
local control_mean = r(mean)
di `control_mean'
*16303.758  // avg. debt to family and freidns
di 100*`debt_decrease'/`control_mean'
*-40.510456 // total debt (win. at 5%) to family and freinds reduced by ca. 41%

*Page 16
/*"Consistent with the role of savings as a substitute for borrowing for 
self-insurance, we find no impact on long-term borrowing amounts or 
categories, where the coefficients are close to zero."*/
use "$inputPath/impactDatabase.dta", clear
foreach y in w5_longTermBorrowing longTermBorrowingIndex {
	  quietly: reg d.`y' //trick to mark subjects nonmissing in both periods
	  egen t1 = max(e(sample)), by(idBaseSurvey)  
	  reghdfe `y' c.accountAccess#c.post post if t1 == 1, ///
	  abs(idBaseSurvey) vce(cluster groupId) 
	  drop t1
 }
/*The regression output shows that the impact is not significant */

// CONSUMPTION CUTBACKS
*Page 17
/*"For the individual items, this frequency ranges from 9% to 52%, with the 
largest proportion of participants reducing clothing, eating out and meat 
consumption."*/
use "$inputPath/impactDatabase.dta", clear
foreach y in mealsCutback* meatCutback* medicinesCutback* schoolSuppliesCutback* ///
clothingCutback* schoolSnacksCutback* transportCutback* eatingOutCutback* {
	qui sum `y' if inSample==1 & year==2008
	di r(mean)
}
/*
.10739387
.41183099
.26501269
.20469989
.51818438  largest
.08635334  smallest
.31944835
.42730141
*/

*Page 17
/*"To establish which participants were affected by a shock to their income, we 
asked whether they had experienced a job loss in the household or a significant 
business downturn. Forty percent of participants experienced at least one such 
shock in the three months preceding the follow-up survey."*/
use "$inputPath/impactDatabase.dta", clear
*Getting total first
sum economicShock if post==1 & inSample==1 
local total = r(N)
di `total'
*3582
sum economicShock if economicShock==1 & post==1 & inSample==1
local shock = r(N)
di `shock'
*1435
di 100*`shock'/`total'
*40.061418 // ca. 40% of participants experienced a shock

*Page 17
/*"Using the same specifications as in our other impact estimates, the effects
on the probability of experiencing a shock is -0.03 from a baseline of 0.36 with a p-value of 0.18"*/
use "$inputPath/impactDatabase.dta", clear
reghdfe economicShock c.accountAccess#c.post post,  ///
	abs(idBaseSurvey) vce(cluster groupId) 
local treatment_eff_shock = _b[c.accountAccess#c.post]
di `treatment_eff_shock'
*-.02942801 // Trat. effect on prob. of shock: -0.03
test c.accountAccess#c.post 
di r(p)
*.17848235 //  p-value of treat. effect : 0.18 
sum economicShock if accountAccess == 0 & post == 1 
local baseline_mean = r(mean)
di `baseline_mean'
*.36357527 // Baseline prob. of experiencing a shock: 0.36

*Page 17 Endnote 22								
/*"Table A1 in the Appendix shows consumption cutbacks for the full population, 
including those who did not experience a shock. Again, the frequency of reducing 
consumption is reduced for almost all items, however, the overall impact is no 
longer statistically significant (with an AES p-value of 0.461)."*/
preserve	
	eststo clear
	local i = 1
	foreach y in mealsCutback meatCutback medicinesCutback ///
		schoolSuppliesCutback clothingCutback schoolSnacksCutback ///
		transportCutback eatingOutCutback { 

		reghdfe `y' c.accountAccess#c.post post if inSample == 1, ///
			abs(idBaseSurvey) vce(cluster groupId) 
		eststo
		
		estadd local fixeff = "Yes"
		
		sum `y' if accountAccess == 0 & post == 1 // control's mean outcome
		if (abs(`r(mean)') < 100) {
			estadd local control_mean = trim("`: display %12.3fc r(mean)'")
		} 
		else {
			estadd local control_mean = trim("`: display %12.0fc r(mean)'")
		}
		
		//AES calculation, step 1: normalizes variables
		sum `y' if accountAccess==0 //computes sd
		gen aes_cc`i' = `y' / r(sd) //normalizes outcome variable
		
		local i = `i' + 1 //updates counter	

	}
	
	//AES calculation, step 2: reshapes the data to implement regression
	// we keep only variables required
	keep aes_cc* idBaseSurvey post groupId accountAccess
	reshape long aes_cc, i(idBaseSurvey post) j(out)
	
	//AES: Implements regression
	reg aes_cc (c.accountAccess#c.post)#i.out c.accountAccess#i.out ///
	c.post#i.out i.out, r cluster(groupId) 
	
	//AES: computes AES
	lincom( (1.out#c.accountAccess#c.post + 2.out#c.accountAccess#c.post + ///
		3.out#c.accountAccess#c.post + 4.out#c.accountAccess#c.post + ///
		5.out#c.accountAccess#c.post + 6.out#c.accountAccess#c.post + ///
		7.out#c.accountAccess#c.post + 8.out#c.accountAccess#c.post ) / 8)	

	local aes_se = trim("`: display %12.3fc r(se)'")
	local aes_p = 2*ttail(`r(df)',abs(`r(estimate)' / `r(se)'))
	// stores stars for coefficient
	if (`aes_p' <= 0.1 & `aes_p' > 0.05 ) { 
		local aes_b = trim("`: display %12.3fc r(estimate)'*")
	}
	else if (`aes_p' <= 0.05 & `aes_p' > 0.01 ) { 
		local aes_b = trim("`: display %12.3fc r(estimate)'**")
	}
	else if (`aes_p' <= 0.01 ) { 
		local aes_b = trim("`: display %12.3fc r(estimate)'***")
	}
	else {
		local aes_b = trim("`: display %12.3fc r(estimate)'")
	}
	
	di "`aes_b'" // p-value of the AES using the expanded sample
restore

*Page 18
/*"Using a triple difference specification, we find
that for participants who were offered an account, the overall increase in consumption cutbacks
associated with an income shock (measured as the number of items for which consumption had
to be reduced) was mitigated by 47%."*/
use "$inputPath/impactDatabase.dta", clear
* Triple difference for consumption cutbacks
reghdfe numberConsumptionCutbacks c.economicShock#c.accountAccess#c.post /// 	
c.accountAccess#c.post c.economicShock#c.post post, vce(cluster groupId) abs(idBaseSurvey)   
local shock_acc_post = _b[c.economicShock#c.accountAccess#c.post]
di `shock_acc_post'
*-.39955245	// average change of effect of economic shock effect on cutbacks
local shock_post = _b[c.economicShock#c.post]
di `shock_post'  // baseline effect of shock on cutbacks
*.84168404
di 100*`shock_acc_post'/`shock_post'
*-47.470598 // Relative decrease of cutbacks on shock with treatment: 47%

*Page 18
/*"In the treatment group, a negative income shock in the post-treatment period 
was associated with a 0.43 increase in cutbacks, compared to a 0.86 increase in 
the control group (with a p-value of the difference equal to 0.012)."*/
use "$inputPath/impactDatabase.dta", clear
reg d.numberConsumptionCutbacks
egen t1 = max(e(sample)), by(idBaseSurvey)
reghdfe numberConsumptionCutbacks i.accountAccess#c.economicShock#c.post post if t1 == 1,  ///
	abs(idBaseSurvey) vce(cluster groupId) 
di "`: display %12.2fc _b[0.accountAccess#c.economicShock#c.post]'" 
di "`: display %12.2fc _b[1.accountAccess#c.economicShock#c.post]'" 
lincom _b[0.accountAccess#c.economicShock#c.post] - _b[1.accountAccess#c.economicShock#c.post]
di "`: display %12.4fc 2*ttail(r(df),abs(`r(estimate)'/`r(se)'))'" 
*.4306419 = 0.50

// LENDING
*Page 19
/*"However, there is a clear difference in the
response between the 69% who indicated in the baseline survey that they always or frequently regret
not having saved more and those who did not (Column 2)"*/ 
use "$inputPath/impactDatabase.dta", clear
*Get total first, only want 2008 to not have duplicates
sum regretsNotSaving if year==2008
local total = r(N)
di `total'
*4118
sum regretsNotSaving if regretsNotSaving==1 & year==2008
local regretsNotSaving = r(N)
di `regretsNotSaving'
*2848
di 100*`regretsNotSaving'/`total'
*69.159786 // ca. 69% of subjects report that they regret not saving more

// SUBJECTIVE WELL-BEING
*Page 21 Endnote 27
/* In addition to these broader measures of well-being, the treatment decreased the probability of participants stating
that they were intimidated to enter a bank by 4.8% from a baseline of 46% (p=0.06)*/ 
use "$inputPath/impactDatabase.dta", clear
reg d.binIntimBank
egen t1 = max(e(sample)), by(idBaseSurvey)
xtreg binIntimBank c.accountAccess#c.post post if t1 == 1, fe ///
  vce(cluster groupId) 
// Constant - 0.46, baseline intimidation
// Treatment effect - -0.048 with p=0.06

// OTHER OUTCOMES
*Page 23
*"Our results, however, find no significant effect on household dynamics."
use "$inputPath/impactDatabase.dta", clear
foreach y in savingDecision hideSavingsFamily hideSavingsSO ///
 borrowSO troubleSO {
	 quietly: reg d.`y'
	 egen t1 = max(e(sample)), by(idBaseSurvey)
	 reghdfe `y' c.accountAccess#c.post post if t1 == 1,  vce(cluster groupId) abs(idBaseSurvey)
	 drop t1 
}
*The regressions show no significant effects

*Page 23
*"We also find no effects on bulky expenditures."
use "$inputPath/impactDatabase.dta", clear
foreach y in boughtElectronics madeInvestment improveHome ///
  prePayFE {
	 quietly: reg d.`y'
	 egen t1 = max(e(sample)), by(idBaseSurvey)
	 reghdfe `y' c.accountAccess#c.post post if t1 == 1, vce(cluster groupId) abs(idBaseSurvey)
	 drop t1 
}
*The regressions show no significant effects

*-------------------------------------------------------------------------------
* II.3.b. Section 3.2: Take-up
*-------------------------------------------------------------------------------

*Page 23
/*"For heads of house-hold, take-up is 5 percentage points lower, a reduction of 
11 percent compared to the overall take-up rate."*/
use "$inputPath/impactDatabase.dta", clear
qui reg activeUser female age c.age#c.age educationYears childrenAtHome ///
		lnIncomePerCap hasPrevAccount headHousehold ///
		conflictsMoney sociallyTaxed regretsNotSaving ///
		hyperbolicPreferences fearStolen if post == 0 & ///
		inSample == 1 & accountAccess == 1, vce(cluster groupId) 
local headHousehold = _b[headHousehold]
di 100*`headHousehold'
*-4.5489469 // Absolute difference: take-up is 5% lower
sum activeUser if e(sample) == 1 
local mean_take_up = r(mean)
di 100*`mean_take_up'
*39.659367  // 40% Baseline take-up
di 100*`headHousehold'/`mean_take_up'
*-11.470044  // Relative difference in take-up for HH -11%

// Using a different take-up model:
use "$inputPath/impactDatabase.dta", clear
qui reg activeUser female age c.age#c.age educationYears childrenAtHome ///
		lnIncomePerCap hasPrevAccount headHousehold ///
		conflictsMoney lentFamily owesFamily regretsNotSaving ///
		hyperbolicPreferences fearStolen if post == 0 & ///
		inSample == 1 & accountAccess == 1, vce(cluster groupId) 
sum activeUser if e(sample) == 1 
local headHousehold = _b[headHousehold]
di 100*`headHousehold'
*-4.5575747 = 5%
sum activeUser if e(sample) == 1 
local mean_take_up = r(mean)
di 100*`mean_take_up'
*39.659367
di 100*`headHousehold'/`mean_take_up'	
*-11.491799 = -11%	
*11% for both regressions

*Page 24
/*"having conflicts with one's partner over monetary issues increases take-up by 
5 percentage points, an increase of 11 percent."*/
*"Take-up of the Account" table
use "$inputPath/impactDatabase.dta", clear
qui reg activeUser female age c.age#c.age educationYears childrenAtHome ///
		lnIncomePerCap hasPrevAccount headHousehold ///
		conflictsMoney sociallyTaxed regretsNotSaving ///
		hyperbolicPreferences fearStolen if post == 0 & ///
		inSample == 1 & accountAccess == 1, vce(cluster groupId) 
local conflictsMoney = _b[conflictsMoney]
di 100*`conflictsMoney'
*4.5520179 = 5%
sum activeUser if e(sample) == 1 
local mean_take_up = r(mean)
di 100*`mean_take_up'
*39.659367
di 100*`conflictsMoney'/`mean_take_up'
*11.477787 = -11%

//Alternative take-up model:
use "$inputPath/impactDatabase.dta", clear
qui reg activeUser female age c.age#c.age educationYears childrenAtHome ///
		lnIncomePerCap hasPrevAccount headHousehold ///
		conflictsMoney lentFamily owesFamily regretsNotSaving ///
		hyperbolicPreferences fearStolen if post == 0 & ///
		inSample == 1 & accountAccess == 1, vce(cluster groupId) 
sum activeUser if e(sample) == 1 
local conflictsMoney = _b[conflictsMoney]
di 100*`conflictsMoney'
*4.5585809 = 5%
sum activeUser if e(sample) == 1 
local mean_take_up = r(mean)
di 100*`mean_take_up'
*39.659367
di 100*`conflictsMoney'/`mean_take_up'	
*11.494336 = 11%	
*So it's 11% for both regressions

*Page 24 
/*"However, we find that these pure lenders are 6 percentage points
more likely to open and use the account, an increase of 15% "*/
use "$inputPath/impactDatabase.dta", clear
qui reg activeUser female age c.age#c.age educationYears childrenAtHome ///
		lnIncomePerCap hasPrevAccount headHousehold ///
		conflictsMoney sociallyTaxed regretsNotSaving ///
		hyperbolicPreferences fearStolen if post == 0 & ///
		inSample == 1 & accountAccess == 1, vce(cluster groupId) 
local sociallyTaxed = _b[sociallyTaxed]
di 100*`sociallyTaxed'
*5.7737972 = 6% // Absolute increase of Take-Up for pure lenders
sum activeUser if e(sample) == 1 
local mean_take_up = r(mean)
di 100*`mean_take_up'
*39.659367	// Baseline take-up
di 100*`sociallyTaxed'/`mean_take_up'
*14.55847 // Increase of ca. 15%

*Page 24 Endnote 31							
/*"This is consistent with Ashraf et al. (2006b), who find that individuals with hyperbolic time preferences demon-
strate a preference for commitment devices. Testing for subsequent usage, we find that being hyperbolic does not
reduce the probability of using the account conditional on opening one, and contrary to the findings of Ashraf et al.
(2006b), does not lead to a greater variance in the account balance. */
use "$inputPath/impactDatabase.dta", clear
reg activeUser hyperbolicPreferences if post == 0 & openedAccount == 1, vce(cluster groupId)
test hyperbolicPreferences
// .00676372
di  _b[hyperbolicPreferences]
di r(p)
*.79989482
*Treatment does not reduce the prob. of being hyperbolic 
reg sdMonthSavingsAug08Aug09 hyperbolicPreferences if post == 0 & openedAccount == 1, vce(cluster groupId)
test hyperbolicPreferences
di _b[hyperbolicPreferences]
//1929.2129
di r(p)
*.44435615
*There is no significantly greater variance in the account balance 

*-------------------------------------------------------------------------------
* II.3.c. Section 3.3: Robustness Checks
*-------------------------------------------------------------------------------

*Page 25-26
/*"Participants receiving the treatment rated the difficulty of the survey 
process as 0.04 points higher compared to 2.45 of the control group ... 
satisfaction with FE as 0.01 point lower compared to compared to 6.38 of the 
control group with neither effect being close to statistical significance."*/
*"Demand Effects" table
use "$inputPath/impactDatabase.dta", clear
foreach y in difficultySurvey satisfactionFE {
	reg `y' accountAccess if post == 1, vce(cluster groupId) 
	*calculating t-statistic
	local t = _b[accountAccess]/_se[accountAccess]
	*Calculating p-value:
	di 2*ttail(e(df_r),abs(`t'))
}
*.36247447
*.80379659
*As seen from the output, the p-values do not indicate statistical significance

*Page 26
*"14.2% of participants could not be found for the follow-up survey"
*Counting only for year 2009 since we have 2 observations for each individual
use "$inputPath/impactDatabase.dta", clear
sum inSample if inSample != 1 & year==2009
local attrition = r(N)
di `attrition'
*593
sum accountAccess if accountAccess != . & year==2009
local all_participants = r(N)
di `all_participants'
*4175
di 100*`attrition'/`all_participants'
*14.203593  // 14.2 & Follow-up attrition

*Page 26
*"attrition is 2.9 percentage points higher in the treatment group."
*"Baseline Summary Statistics and Balance of Randomization" table result
use "$inputPath/impactDatabase.dta", clear
gen attrition = (inSample != 1) if post==0
sum attrition if accountAccess == 0
local c2r1 = trim("`: display %12.2fc r(mean)'") 
local c2r2 = trim("`: display %12.2fc r(sd)'") 
reg attrition accountAccess if post==0
local attrition_pct = _b[accountAccess]
di `attrition_pct' 
*.02855845 // ca. 2.9% higher attrition in control group

*Page 27
/*"That proportion corresponds to the difference in attrition rates between the 
treatment and control group as a poportion of the retention rate of the 
treatment group, which is in our case 3.3%."*/
use "$inputPath/impactDatabase.dta", clear
*How many were assigned to treatment?
	count if accountAccess==1 & post == 0
	local treat_total = `r(N)'
*How many were assigned to control?
	count if accountAccess==0 & post == 0
	local control_total = `r(N)'
*What proportion of those assigned to treatment got it?
	count if accountAccess==1 & inSample==1 & post == 0
	local treat_incl = `r(N)'/`treat_total'
*What proportion of those assigned to control got it?
	count if accountAccess==0 & inSample==1 & post == 0
	local control_incl = `r(N)'/`control_total'
*Calculate trimming proportion
	local tp = abs(`treat_incl'-`control_incl') / ///
		(max(`treat_incl',`control_incl'))
di 100*`tp'
*3.2588172 // Retention rate of treatment group 3.3%

*Page 27
/*"Finally, being in the treatment group reduces the consumption cutback index 
for individuals who had a shock by 0.37 units without, and by 0.36 with 
attrition weights."*/
use "$inputPath/impactDatabase.dta", clear
reg d.numberConsumptionCutbacks
egen t1 = max(e(sample)), by(idBaseSurvey)
xtreg numberConsumptionCutbacks c.accountAccess#c.post post if ///
 t1 == 1 & economicShock2009 == 1, fe ///
 vce(cluster groupId) 
di `: display %12.2fc _b[c.accountAccess#c.post]' 
*-.37
*This next part is from the "Inverse Probability Weighting" table, Column 5 
xtreg numberConsumptionCutbacks c.accountAccess#c.post post if ///
 t1 == 1 & economicShock2009 == 1 [pw=ipw], fe ///
 vce(cluster groupId) 
di `: display %12.2fc _b[c.accountAccess#c.post]' 
*-.36

*Page 27 Endnote 34								
/*"The following variables are used to construct the weights: all main outcome 
variables at baseline, all variables for which there is a significant difference 
between attritors and non-attritors in Table 1, and a number of additional 
characteristics which assure that conditional on all weight variables, being in 
the treatment group is no longer statistically significantly associated with 
attrition (with a p-value of 0.964)."*/
*If inSample==0 then one is an attritor
use "$inputPath/impactDatabase.dta", clear
reg inSample accountAccess if post==0, vce(cluster groupId)
test accountAccess
di r(p)
reg inSample accountAccess if post==0 [pw = ipw], vce(cluster groupId)
test accountAccess
di r(p)
*.957 // p-value of 0.96; statistically insignificant

*-------------------------------------------------------------------------------
* II.4. Section 4: Discussion and Conclusion
*-------------------------------------------------------------------------------

*Page 29
/*"For the two measures, the effect corresponds in magnitude to about half or 
more of the change in the measure associated with a job loss or severe income 
shock"*/
// see code above concerning the introduction section

*Page 29
/*At the same time, our survey results showing that
at baseline, 46% of participants were intimidated by entering a bank also suggest that reducing
mental barriers or general trust by providing endorsement by a credible institution may play an
important role in encouraging take-up, consistent with the findings of Cole et al. (2013) for the
case of micro-insurance"*/
count if intimidatedBank2008 < 3 & post == 0
local intb = `r(N)'
*1,885
count if intimidatedBank2008 != . & post == 0
*4,114
di 100*`intb'/`r(N)' 
*45.795538 // ca. 46% of people in the baseline are intimidated 46%



capture log close

********************************************************************************
* END
********************************************************************************
